//
//  BattleLoadingLayer.cpp
//  airfight
//
//  Created by aaron more on 12-8-21.
//  Copyright (c) 2012年 moonriver. All rights reserved.
//

#include <iostream>
#include "BattleLoadingLayer.h"
#include "FighterPrototypeParser.h"
#include "BattleActionLayer.h"
#include "EnemyPrototypeParser.h"
#include "StagePrototypeParser.h"
#include "TracePrototypeParser.h"
#include "BonusPrototypeParser.h"
#include "SimpleAudioEngine.h"

//#include "StagePrototypes.h"
//#include "Stage.h"

BattleLoadingLayer::~BattleLoadingLayer()
{
    
}

bool BattleLoadingLayer::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    cover = CCSprite::create(s_pCover);
    cover->setAnchorPoint(ccp(0,0));
    
    this->addChild(cover,0,1);
    cover->setPosition(ccp(0,0));

    return true;
}

void BattleLoadingLayer::update(float dt)
{
    
}

void BattleLoadingLayer::startLoading()
{
    loadingPrototypes();
//    StagePrototypes *prototype = StagePrototypes::getInstance();
//    Stage *stage = prototype->getStageByID(1);
//    CCArray *a = stage->getStartEnemyIDs(10);
//    
//    CCLog("distance = %d",a->count());
    int fighterID = 1;
    int stageID = 1;
    //CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("11111.mp3");
//    CCDictionary *params = CCDictionary::create();
//    params->setObject(CCInteger::create(fighterID),"fighterid");
//    params->setObject(CCInteger::create(stageID),"stageid");
//    CCLayer* actionLayer = BattleActionLayer::create(params);
    ((CCLayerMultiplex*)m_pParent)->addLayer(BattleActionLayer::getInstance());
    ((CCLayerMultiplex*)m_pParent)->switchTo(1);
    //actionLayer->retain();
}

void BattleLoadingLayer::onEnter()
{
    CCLayer::onEnter();
    parent = (CCScene*)(this->getParent()->getParent());
    scheduleOnce(schedule_selector(BattleLoadingLayer::startLoading), 2);
}

void BattleLoadingLayer::onExit()
{
    CCLayer::onExit();
}

void BattleLoadingLayer::loadingPrototypes()
{
    FighterPrototypeParser::formatWithXMLFile("data/player_fighter.xml"); //加载用户小飞机原型
    TracePrototypeParser::formatWithXMLFile("data/trace.xml");// 加载移动路径数据原型
    EnemyPrototypeParser::formatWithXMLFile("data/enemy_fighter.xml");// 加载敌机数据原型
    StagePrototypeParser::formatWithXMLFile("data/stage.xml");// 加载场景数据原型
    BonusPrototypeParser::formatWithXMLFile("data/bonus.xml");//掉落物数据原型
    
}
 
